Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Baynestests #33

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Planet(val name: String, val techLevel: TechLevel, val resourceLevel: Reso
} else if (government.governmentType == GovernmentType.Monarchy) {
chance += 1
}
return chance > -1
return chance > 19
}

fun rollForPolice(): Boolean {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.communistutopia.spacetrader.view

import android.annotation.SuppressLint
import android.arch.lifecycle.Observer
import android.arch.lifecycle.ViewModelProviders
import android.content.Context
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.ArrayAdapter
import android.widget.Toast
import android.transition.Slide
import android.transition.TransitionManager
import android.view.Gravity
import android.view.LayoutInflater
import android.widget.*
import com.communistutopia.spacetrader.R
import com.communistutopia.spacetrader.viewmodel.LocationViewModel
import kotlinx.android.synthetic.main.location_activity.*
Expand All @@ -16,7 +21,7 @@ class LocationActivity: AppCompatActivity() {
private lateinit var viewModel: LocationViewModel
//lateinit var piratePopUp: PopupWindow
//lateinit var policePopUp: PopupWindow
//ateinit var closePopupBtn: Button
lateinit var closePopupBtn: Button


@SuppressLint("ResourceType")
Expand Down Expand Up @@ -48,12 +53,20 @@ class LocationActivity: AppCompatActivity() {
//Toast.makeText(this, "Traveled!", Toast.LENGTH_SHORT).show()
var item = planets_spinner.selectedItem as LocationViewModel.TravelSpinnerEntry
viewModel.travelToPlanet(item.solarSystem, item.planet)
/*viewModel.policeEvent.observe(this, Observer<Any> {
val event = viewModel.player.value!!.location.market.event.toString()
val planet = item.planet.name
val duration = Toast.LENGTH_LONG
Toast.makeText(
this,
"Traveled to $planet, which is experiencing a $event",
duration
).show()
viewModel.policeEvent.observe(this, Observer<Any> {
//setup for police popup
val layoutInflater =
[email protected](Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val customView = layoutInflater.inflate(R.layout.police_popup, null)
var closePopupBtn = customView.findViewById<Button>(R.id.closePopupBtn)
closePopupBtn = customView.findViewById<Button>(R.id.button_popup)
var popupWindow = PopupWindow(
customView,
LinearLayout.LayoutParams.WRAP_CONTENT,
Expand All @@ -69,8 +82,10 @@ class LocationActivity: AppCompatActivity() {
slideOut.slideEdge = Gravity.RIGHT
popupWindow.exitTransition = slideOut
//display the popup window

TransitionManager.beginDelayedTransition(findViewById(R.layout.location_activity))
popupWindow.showAtLocation(
findViewById(R.layout.location_activity),
root_layout,
Gravity.CENTER,
0,
0
Expand All @@ -79,6 +94,7 @@ class LocationActivity: AppCompatActivity() {
//close the popup window on button click
closePopupBtn.setOnClickListener {
popupWindow.dismiss()
finish()
}
})

Expand All @@ -87,7 +103,7 @@ class LocationActivity: AppCompatActivity() {
val layoutInflater =
[email protected](Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val customView = layoutInflater.inflate(R.layout.pirate_popup, null)
var closePopupBtn = customView.findViewById<Button>(R.id.closePopupBtn)
var closePopupBtn = customView.findViewById<Button>(R.id.button_popup)
var popupWindow = PopupWindow(
customView,
LinearLayout.LayoutParams.WRAP_CONTENT,
Expand All @@ -104,7 +120,7 @@ class LocationActivity: AppCompatActivity() {
popupWindow.exitTransition = slideOut
//display the popup window
popupWindow.showAtLocation(
findViewById(R.layout.location_activity),
root_layout,
Gravity.CENTER,
0,
0
Expand All @@ -113,17 +129,11 @@ class LocationActivity: AppCompatActivity() {
//close the popup window on button click
closePopupBtn.setOnClickListener {
popupWindow.dismiss()
finish()
}
})*/
val event = viewModel.player.value!!.location.market.event.toString()
val planet = item.planet.name
val duration = Toast.LENGTH_SHORT
Toast.makeText(
this,
"Traveled to $planet, which is experiencing a $event",
duration
).show()
finish()
})


}
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/location_activity.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
Expand Down
29 changes: 16 additions & 13 deletions app/src/main/res/layout/pirate_popup.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="#000"
android:padding="10px">

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linear_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#c7bf98"
android:padding="20dp"
>
<TextView
android:id="@+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pirates raided your ship and took half your cargo!!!"
android:textColor="#fff"/>

android:text="Pirates raided your ship and took half your cargo"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
/>
<Button
android:id="@+id/button_popup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Close"
android:id="@+id/closePopupBtn"/>

android:text="Close Me"
/>
</LinearLayout>
28 changes: 15 additions & 13 deletions app/src/main/res/layout/police_popup.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="#000"
android:padding="10px">

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linear_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#c7bf98"
android:padding="20dp"
>
<TextView
android:id="@+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Police Officers raided your ship and took half your cargo and credits!!!"
android:text="Police Officers raided your ship and took half of your cargo and credits"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
/>


<Button
android:id="@+id/button_popup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Close"
android:id="@+id/closePopupBtn"/>

android:text="Close Me"
/>
</LinearLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.communistutopia.spacetrader

/**
* @author Nicholas Bayne Grubb
* [email protected]
*/
import com.communistutopia.spacetrader.model.*
import junit.framework.Assert.assertEquals
import junit.framework.Assert.assertTrue
import org.junit.AfterClass
import org.junit.BeforeClass
import org.junit.Test

class PlanetAttributeTests {
companion object {
lateinit var government: Government
lateinit var resourceLevel: ResourceLevel
lateinit var techLevel: TechLevel

@BeforeClass
@JvmStatic
fun setup() {
government = Government(GovernmentType.Anarchy)
resourceLevel = ResourceLevel(ResourceLevelType.DESERT)
techLevel = TechLevel(TechLevelType.HiTech)
}

@AfterClass
@JvmStatic
fun teardown() {

}
}

@Test
fun testRandomTypeGenerators() {
var governmentType = GovernmentType.randomGovernmentType()
var resourceLevelType = ResourceLevelType.randomResourceLevelType()
var techLevelType = TechLevelType.randomTechLevelType()
assertTrue(governmentType is GovernmentType)
assertTrue(resourceLevelType is ResourceLevelType)
assertTrue(techLevelType is TechLevelType)
}

@Test
fun testGovernmentHashCodeAndEquals() {
var g1 = Government(GovernmentType.Anarchy)
var g2 = Government(GovernmentType.Anarchy)
var g1hash = g1.hashCode()
var g2hash = g2.hashCode()
assertEquals(g1hash, g2hash)
assertTrue(g1.equals(g2))
}

@Test
fun testResourceHashCodeAndEquals() {
var r1 = ResourceLevel(ResourceLevelType.DESERT)
var r2 = ResourceLevel(ResourceLevelType.DESERT)
var r1hash = r1.hashCode()
var r2hash = r2.hashCode()
assertEquals(r1hash, r2hash)
assertTrue(r1 == r2)
}

@Test
fun testTechHashCodeAndEquals() {
var a = TechLevel(TechLevelType.HiTech)
var b = TechLevel(TechLevelType.HiTech)
var ahash = a.hashCode()
var bhash = b.hashCode()
assertEquals(ahash, bhash)
assertTrue(a == b)
}

@Test
fun testGovernmentToString() {
var str = government.toString()
assertEquals(str, "Government(governmentType=Anarchy)")
}

@Test
fun testResourceToString() {
var str = resourceLevel.toString()
assertEquals(str, "ResourceLevel(resourceLevel=DESERT)")
}

@Test
fun testTechToString() {
var str = techLevel.toString()
assertEquals(str, "TechLevel(techLevel=HiTech)")
}
}
69 changes: 69 additions & 0 deletions app/src/test/java/com/communistutopia/spacetrader/PlanetTests.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.communistutopia.spacetrader

import com.communistutopia.spacetrader.model.*
import org.junit.AfterClass
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.BeforeClass
import org.junit.Test

/**
* @author Nicholas Bayne Grubb
* [email protected]
*/

class PlanetTests {
companion object {
lateinit var planet: Planet

@BeforeClass
@JvmStatic
fun setup() {
planet = Planet(
"Bayne",
TechLevel(TechLevelType.HiTech),
ResourceLevel(ResourceLevelType.NOSPECIALRESOURCES),
Government(GovernmentType.Anarchy)
)
}

@AfterClass
@JvmStatic
fun teardown() {

}
}

@Test
fun testRandomEvent() {
var event = planet.rollForRandomEvent()
assertTrue(event is Event)
}

@Test
fun testRandomPirate() {
var pirateEncounter = planet.rollForPirates()
assertTrue(pirateEncounter is Boolean)
}

@Test
fun testRandomPolice() {
var policeEncounter = planet.rollForPolice()
assertTrue(policeEncounter is Boolean)
}

@Test
fun testToString() {
var toString = planet.toString()
var toStringResult = "Planet(" + "\n" +
"name='Bayne', " + "\n" +
"techLevel=TechLevel(techLevel=HiTech), " + "\n" +
"resourceLevel=ResourceLevel(resourceLevel=NOSPECIALRESOURCES), " + "\n" +
"government=Government(governmentType=Anarchy), " + "\n" +
"market=Market(\ntechLevel=TechLevel(techLevel=HiTech), \n" +
"resourceLevel=ResourceLevel(resourceLevel=NOSPECIALRESOURCES), \n" +
"government=Government(governmentType=Anarchy)\n)" + "\n" +
")"
assertEquals(toString, toStringResult)
}
}